{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "08d0f6cd",
   "metadata": {},
   "source": [
    "###  week07 课堂练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "847d4692",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a']\n",
      "['o', 'n', \"'\", 't', ' ', 'p', 'a']\n",
      "['o', 'n', 't', ' ', 'p', 'a']\n",
      "['o', 'n', 't', ' ', 'a', 'p']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n"
     ]
    }
   ],
   "source": [
    "# Author: Jinkai\n",
    "# Date: week07 列表练习 & 初始字典\n",
    "\n",
    "# 目标： “Don't panic” ==> \"on tap\"\n",
    "\n",
    "# 方法一： 使用list的方法完成\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)  # list() 可以将 str  to(转)  list\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "# 1.删除后面四个元素 a n i c\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "print(plist)\n",
    "# 2. 删除 D  ‘\n",
    "plist.remove('D')\n",
    "print(plist)\n",
    "plist.pop(2)\n",
    "print(plist)\n",
    "\n",
    "# 3. 数学案例： 计算 （(a+b)*(c+d)）\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "#['o','n','t',' '][ a    ,   p     ]\n",
    "print(plist)\n",
    "\n",
    "# 4. 数据插入  实现：’t‘ 和’ ‘ 的位置转换\n",
    "# plist.insert(2,plist.pop(3))\n",
    "# print(plist)\n",
    "# print(plist.pop(2))  # 1，代表删除的内容的值 2，他删除了plist的这个值\n",
    "plist.insert(3,plist.pop(2))\n",
    "print(plist)\n",
    "# 5. list to str\n",
    "new_phrase = ''.join(plist)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2aa51c35",
   "metadata": {},
   "source": [
    "###  知识点 元组\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac1c872b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author: Jinkai\n",
    "# Date: week07 列表练习 & 初始字典\n",
    "\n",
    "t = 12345, 54321, 'hello!'\n",
    "print(t)\n",
    "print(type(t))\n",
    "t.\n",
    "\n",
    "# import time\n",
    "# print(time.localtime())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d97a2ee7",
   "metadata": {},
   "source": [
    "  ### 课本练习 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c958b790",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author: Jinkai\n",
    "# Date: week07 列表练习 & 初始字典\n",
    "# 方法二： 使用切片的方法实现\n",
    "\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)  # list() 可以将 str  to(转)  list\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "\n",
    "on_str = ''.join(plist[1:3])\n",
    "print(on_str)\n",
    "new_phrase = on_str+ ''.join(plist[5]+plist[4]+plist[7]+plist[6])\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
